<template>
  <view class="content">
    <view v-if="!loadingFlag">
      <view class="list-block">
        <view class="item-block">
          <view class="item-icon">
            <u-icon name="account-fill" color="#2979ff" size="50"></u-icon>
          </view>
          <view class="item-box">
            <view class="item-information">
              <view class="item-name">{{personnelInformation.nickname}}</view>
              <view class="item-phone">{{personnelInformation.mobile}}</view>
            </view>
            <view class="item-company">
              <!-- <view class="mr-10">男 | </view> -->
              <view class="mr-10">在职</view>
              <!-- <view>354635463546546546</view> -->
            </view>
          </view>
        </view>
        <view></view>
      </view>
      <view class="personal-information">
        <view class="persional-content">
          <view>所属部门：</view>
          <view>{{personnelInformation.deptName}}</view>
        </view>
        <view class="persional-content">
          <view>岗位：</view>
          <view>{{personnelInformation.postNameGather}}</view>
        </view>
        <!-- <view class="persional-content">
          <view>入职时间：</view>
          <view>2022.12.31</view>
        </view>
        <view class="persional-content">
          <view>离职时间：</view>
          <view>2023.12.31</view>
        </view> -->
        <view class="persional-content">
          <view>联系电话：</view>
          <view>{{personnelInformation.mobile}}</view>
        </view>
        <!-- <view class="persional-content">
          <view>电子邮箱：</view>
          <view>351654@123.com</view>
        </view>
        <view class="persional-content">
          <view>家庭住址：</view>
          <view>北京市嫂家分店</view>
        </view>
        <view class="persional-content">
          <view>紧急联系人：</view>
          <view>as冷冻电镜看好你</view>
        </view> -->
        <view class="persional-content">
          <view>登录账号：</view>
          <view>{{personnelInformation.mobile}}</view>
        </view>
      </view>
      <view class="more-information pt-10">
        <view class="more-text">更多信息</view>
        <u-line color="#2979ff"></u-line>
        <view class="more-content">
          <view class="more-box" @click="trainingRecord">培训记录</view>
          <!-- <view class="more-box">考试记录</view>
          <view class="more-box">持证情况</view>
          <view class="more-box">安全奖惩</view> -->
        </view>
      </view>
    </view>
    <u-loading-page :loading="loadingFlag" bg-color="#e8e8e8"></u-loading-page>
  </view>
</template>

<script>
import { getAllUserApi } from "@/apis/safetyProductionResponsibilitySystem/safetyProductionResponsibility.js";
export default {
  data() {
    return {
      params: {
        pageNo: 1,
        pageSize: 10,
        id: "",
      },
      list: [],
      pushState: true,
      /* 人员信息 */
      personnelInformation: null,
      /* 加载标识 */
      loadingFlag: true
    };
  },
  onPullDownRefresh() {
    this.getDangerEditList(
      Object.assign(this.params, { pageNo: 1, pageSize: 10 })
    );
  },
  onReachBottom() {
    if (this.pushState)
      this.getDangerEditList(
        Object.assign(this.params, { pageNo: this.params.pageNo + 1 }),
        false
      );
  },
  onShow() {
  },
  /**
   * 接受路由传参
   */
  onLoad(options) {
    console.log(options)
    if(options.userId){
      this.params.id = options.userId;
      this.getDangerEditList(this.params);
    }
  },

  /**
   * 定义方法
   */
  methods: {
    /* 获取数据 */
    getDangerEditList: function (params, freshState = true) {
      this.loadingFlag = true
      getAllUserApi(params)
        .then((res) => {
          if (freshState) {
            this.pushState = true;
            this.personnelInformation = res.list[0]
            if (this.personnelInformation.postNames) {
              this.personnelInformation.postNameGather = this.personnelInformation.postNames.join(',')
            }
            this.list = res.list;
          } else {
            this.list = this.list.concat(res.list);
          }
          if (res.list.length < this.params.pageSize) this.pushState = false;
          uni.stopPullDownRefresh();
          this.loadingFlag = false
        })
        .catch((err) => console.warn(err));
    },

    /* 培训记录 */
    trainingRecord () {
      uni.navigateTo({
        url: `/pagesTeamSafety/trainingexamination?userId=${this.personnelInformation.userId}&nickname=${this.personnelInformation.nickname}`
      });
    }
  },
};
</script>

<style>
page {
  background-color: #f4f4f4;
}
</style>

<style lang="scss" scoped>
.content {
  padding: 0rpx 25rpx 50rpx 25rpx;
  .list-block {
    .item-block {
      background-color: #ffffff;
      border-radius: 6rpx;
      box-shadow: 0 0 10rpx 0 #f4f4f4;
      margin-top: 25rpx;
      display: flex;
      .item-icon {
        width: 120rpx;
        height: 110rpx;
        margin-top: 20rpx;
      }
      .item-box {
        padding: 20rpx 10rpx;
        .item-information {
          height: 50rpx;
          display: flex;
          .item-name {
            height: 50rpx;
            font-size: 40rpx;
            line-height: 50rpx;
            margin: 0 30rpx;
          }
          .item-phone {
            height: 50rpx;
            font-size: 30rpx;
            line-height: 50rpx;
          }
        }
        .item-company {
          display: flex;
          height: 50rpx;
          font-size: 30rpx;
          line-height: 50rpx;
          margin-left: 30rpx;
          margin-top: 20rpx;
        }
      }
    }
  }
  .personal-information {
    padding: 10rpx 0 20rpx 20rpx;
    margin-top: 25rpx;
    background-color: #ffffff;
    .persional-content {
      font-size: 30rpx;
      line-height: 35rpx;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      display: flex;
      padding: 15rpx 10rpx;
    }
  }
  .more-information {
    margin-top: 25rpx;
    background-color: #ffffff;
    .more-text {
      margin: 20rpx;
    }
    .more-content {
      display: flex;
      // justify-content: space-around;
      padding: 20rpx;
      padding-left: 50rpx;
      .more-box {
        width: 140rpx;
        height: 100rpx;
        background: rgb(49, 202, 184);
        font-size: 25rpx;
        line-height: 100rpx;
        text-align: center;
      }
    }
  }
}
</style>
